
global results 	"/Users/michaelalbertus/Dropbox/Research/Indigenous Communities in Peru/Paper on Recognition and Identity/CPS/Replication/Results"
global data 	"/Users/michaelalbertus/Dropbox/Research/Indigenous Communities in Peru/Paper on Recognition and Identity/CPS/Replication"


********************************************************************************
*FIGURE 3. Survey Respondents by Year of Birth and Age at Time of Community Recognition
********************************************************************************
use "$data/Benaho_com.dta", clear
sdf;
drop if age_ccrecogn<-40 | age_ccrecogn>60
drop if fecha_nac<1920
gen obs=1
collapse (sum) obs, by(fecha_nac)
twoway  (connect obs fecha_nac,m(circle)msize(small)mcolor(navy)lw(medthick)lcolor(navy)),	  					///
		xtitle("Year of birth",margin(medium)size(*1.2)) 														///
		ytitle(" " "# observations",margin(vvsmall)size(*1.2))													///
		legend(symplacement(north) cols(3) size(small) position(12) ring(1) region(fcolor(none)lcolor(none))) 	///			
		xlabel(1920(20)2000,labels labsize(medsmall) valuelabel  ) 												///
		ylabel(0(500)4000,labsize(small)format(%5.0fc)) 														///
		scheme(white_brbg) xsize(5) ysize(3.5) legend(order(1 "Coefficient")) title("Number of observations",size(*1)) saving("$results/fig3a.gph", 		  replace)
		
use "$data/Benaho_com.dta", clear
drop if age_ccrecogn<-40 | age_ccrecogn>60
drop if fecha_nac<1920
gen obs=1
collapse (sum) obs, by(age_ccrecogn)
twoway  (connect obs age_ccrecogn,m(circle)msize(small)mcolor(navy)lw(medthick)lcolor(navy)),	  				///
		xtitle("Age at Year of community recognition",margin(medium)size(*1.2)) 								///
		ytitle(" " "# observations",margin(vsmall)size(*1.2))													///
		legend(symplacement(north) cols(3) size(small) position(12) ring(1) region(fcolor(none)lcolor(none))) 	///			
		xlabel(-40(20)60,labels labsize(medsmall) valuelabel  ) 												///
		ylabel(0(250)4000,labsize(small)format(%5.0fc)) 														///
		scheme(white_brbg) xsize(5) ysize(3.5) legend(order(1 "Coefficient")) title("Number of observations",size(*1)) saving("$results/fig3b.gph", 	 	  replace)		 

graph combine "$results/fig3a.gph" "$results/fig3b.gph",scheme(white_brbg)col(2) xsize(7) ysize(3)

use "$data/Benaho_com.dta", clear
drop if age_ccrecogn<-40 | age_ccrecogn>60
drop if fecha_nac<1920
gen obs=1
collapse (sum) obs, by(t)
twoway  (connect obs t,m(circle)msize(small)mcolor(navy)lw(medthick)lcolor(navy)),	  				///
		xtitle("Survey year",margin(medium)size(*1.2)) 								///
		ytitle(" " "# observations",margin(vsmall)size(*1.2))													///
		legend(symplacement(north) cols(3) size(small) position(12) ring(1) region(fcolor(none)lcolor(none))) 	///			
		xlabel(2008(1)2020,labels labsize(medsmall) valuelabel  ) 												///
		ylabel(0(1000)16000,labsize(small)format(%5.0fc)) 														///
		scheme(white_brbg) xsize(5) ysize(3.5) legend(order(1 "Coefficient")) title("Number of observations",size(*1)) saving("$results/fig3c.gph", 	 	  replace)	

graph combine "$results/fig3a.gph" "$results/fig3b.gph" "$results/fig3c.gph",scheme(white_brbg)col(3) xsize(7) ysize(3)
graph export "$results/fig3.png", replace
erase "$results/fig3a.gph"
erase "$results/fig3b.gph"
erase "$results/fig3c.gph"	


********************************************************************************
*APPENDIX FIGURE. Sampled individuals according to the year of community recognition
********************************************************************************
		
use "$data/Benaho_com.dta", clear
drop if age_ccrecogn<-40 | age_ccrecogn>60
drop if fecha_nac<1920
gen recog_year = fecha_year
replace recog_year = fechareconocimiento_year if fecha_year==.
gen obs=1
collapse (sum) obs, by(recog_year)
twoway  (connect obs recog_year,m(circle)msize(small)mcolor(navy)lw(medthick)lcolor(navy)),	  				///
		xtitle("Year of community recognition",margin(medium)size(*1.2)) 								///
		ytitle(" " "# observations",margin(vsmall)size(*1.2))													///
		legend(symplacement(north) cols(3) size(small) position(12) ring(1) region(fcolor(none)lcolor(none))) 	///			
		xlabel(1920(20)2020,labels labsize(medsmall) valuelabel  ) 												///
		ylabel(0(250)6000,labsize(small)format(%5.0fc)) 														///
		scheme(white_brbg) xsize(5) ysize(3.5) legend(order(1 "Coefficient")) title("Number of observations",size(*1)) saving("$results/fig_app.gph", 	 	  replace)		 
	 

********************************************************************************
*TABLE 2. Community Recognition & Identity
********************************************************************************
* Note: The 'Additional Cohort Comparisons' reported at the bottom of Table 2 are produced following each regression below

use "$data/Benaho_com.dta", clear

gen recog_year = fecha_year
replace recog_year = fechareconocimiento_year if fecha_year==.

*Outcomes
global out 			"p21_3 p801_16"
*Regressions by subsample
#delimit ;
foreach condition in 
"full==1" 
"comm_less10k==1"
"comm_less10k==1 & recog_year<2001"
"comm_less10k==1 & recog_year<1991"
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
test Dexp4_18_25- Dexp2_0_12=0
test Dexp5_26_40- Dexp2_0_12=0
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/Table2.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES, Survey Year FE, YES) drop(i.fecha_nac i.t)
}
}		

********************************************************************************
*TABLE 3. Land and Community Life Mechanism
********************************************************************************
* Note: The 'Additional Cohort Comparisons' reported at the bottom of Table 3 are produced following each regression below

* Note: this generates columns 1,2,6 of Table 3
use "$data/Benaho_com.dta", clear
*Outcomes
global out 			"lnsup_hoy agrperm p801_5"

#delimit ;
foreach condition in 
"comm_less10k==1"
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
test Dexp4_18_25- Dexp2_0_12=0
test Dexp5_26_40- Dexp2_0_12=0
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/Table3.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Communities,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES, Survey Year FE, YES) drop(i.fecha_nac i.t)
}
}	

* Note: this generates columns 3,4,5 of Table 3
use "$data/Bcenagro12_com.dta", replace
*Outcomes
global out 			"Dad_heren Dpropietario Drt_com_sup"
gen mujer=sexo==0
rename educ anoedu2
foreach outcome of varlist $out {
#delimit ;
foreach condition in 
"comm_less10k==1"
{;
#delimit cr
areg `outcome' i.fecha_nac Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
test Dexp4_18_25- Dexp2_0_12=0
test Dexp5_26_40- Dexp2_0_12=0
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/Table3.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES, Survey Year FE, NA) drop(i.fecha_nac)
}
}		


********************************************************************************
*TABLE 4. Placebo Tests Using Untitled Communities
********************************************************************************
use "$data/Benaho_com.dta", clear
keep if status=="Reconocidas por Titular"

*Outcomes
global out 			"p21_3 p801_16"

*Subsamples
#delimit ;
foreach condition in 
"full==1" 
{;
#delimit cr

foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/Table4.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES, Survey Year FE, YES) drop(i.fecha_nac i.t)
}
}		


********************************************************************************
*TABLE 5. Impacts of Recognition in the Highlands Versus the Coast Versus the Amazon
********************************************************************************

use "$data/Benaho_com.dta", clear
*Outcomes
global out 			"p21_3 p801_16"

gen region_nat = 1 if elevation_mean>=1500
replace region_nat = 2 if elevation_mean<1500 & (cdigodepartamento=="24"|cdigodepartamento=="20"|cdigodepartamento=="14"|cdigodepartamento=="13"|cdigodepartamento=="2"|cdigodepartamento=="15"|cdigodepartamento=="11"|cdigodepartamento=="4"|cdigodepartamento=="18"|cdigodepartamento=="23")
replace region_nat = 3 if elevation_mean<1500 & (cdigodepartamento=="21"|cdigodepartamento=="8"|cdigodepartamento=="17"|cdigodepartamento=="25"|cdigodepartamento=="12"|cdigodepartamento=="19"|cdigodepartamento=="10"|cdigodepartamento=="22"|cdigodepartamento=="16"|cdigodepartamento=="1")

*Subsamples
#delimit ;
foreach condition in 
"region_nat==1" 
"region_nat==2" 
"region_nat==3"
{;
#delimit cr

foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/Table5.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES, Survey Year FE, YES) drop(i.fecha_nac i.t)
}
}	


********************************************************************************
*TABLE 6.Alternative Explanations
********************************************************************************

use "$data/Benaho_com.dta", clear

*Outcomes
global out 			"lnGAS_t"
*Regressions by subsample
#delimit ;
foreach condition in 
"full==1" 
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/Table6.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey Year FE, YES) drop(i.fecha_nac i.t)
}
}

*Outcomes
global out 			"p21_3 p801_16"
*Regressions by subsample
#delimit ;
foreach condition in 
"petition1920s==0" 
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/Table6.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey Year FE, YES) drop(i.fecha_nac i.t)
}
}



********************************************************************************
*Appendix I. Descriptive Statistics 
********************************************************************************

use "$data/Benaho_com.dta", clear
tab reg_nat94, gen(nr)
summ p7 p1_08  p21_3 p801_16 nr1 nr2 nr3 Dexp1_bef Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 lnsup_hoy agrperm p801_5 lnGAS_t petition1920s idorig mujer anoedu2 , sep(0)

use "$data/Bcenagro12_com.dta", replace
summ Dad_heren Dpropietario Drt_com_sup


********************************************************************************
*Appendix III. Communities and Populations Represented in ENAHO Sample
********************************************************************************
use "$data/Benaho_com.dta", clear
recode yr_ccrecogn (1900/1940=1) (1941/1950=2) (1951/1960=3) (1961/1970=4) (1971/1980=5) (1981/1990=6) (1991/2000=7) (2001/2010=8) (2011/2020=9), gen(Gyr_ccrecogn)
label def Gyr_ccrecogn 1"Period 1921-1940" 2"Period 1941-1950" 3"Period 1951-1960" 4"Period 1961-1970" 5"Period 1971-1980" 6"Period 1981-1990" 7"Period 1991-2000" 8"Period 2001-2010" 9"Period 2011-2016"
label val Gyr_ccrecogn Gyr_ccrecogn 
tab Gyr_ccrecogn 
preserve 
keep ubigeo Gyr_ccrecogn 
duplicates drop
tab Gyr_ccrecogn 
restore
preserve 
keep comm_id Gyr_ccrecogn 
duplicates drop
tab Gyr_ccrecogn 
restore

********************************************************************************
*Appendix IV. Distribution of Sampled Individuals by Community
********************************************************************************
use "$data/Benaho_com.dta", clear
keep comm_id 
gen obs=1
collapse (sum) obs, by(comm_id)
recode obs (0/24=1)(25/50=2)(51/100=3)(101/150=4)(151/200=5)(201/500=6)(500/1000000=7), gen(robs)
label def robs 1"Less than 25" 2"25 to 50" 3"51 to 100" 4"101 to 150" 5"151 to 200" 6"201 to 500" 7"More than 500"
label val robs robs
tab robs
twoway (histogram obs if obs<500, bcolor(navy)), scheme(white_brbg) xtitle("Sample size by Community")
graph export "$results/fig_iv.png", replace


********************************************************************************
*Appendix IX. Outcomes by Age at Time of Recognition Versus Year of Birth
********************************************************************************

*Reports he/she feels belong to a community
use "$data/Benaho_com.dta", clear
drop if age_ccrecogn<-40 | age_ccrecogn>60
drop if fecha_nac<1920
collapse (mean) p21_3, by(age_ccrecogn)
twoway  (lpolyci p21_3 age_ccrecogn,m(circle)msize(small)mcolor(navy)lw(medthick)),	  		///
		xtitle("Age at Year of community recognition",margin(medium)size(*1.4)) 			///
		ytitle(" " "Reports he/she feels belong to a community",margin(vvsmall)size(*1.4))	///
		legend(symplacement(north) cols(3) size(small) position(12) ring(1) ) 				///			
		xlabel(-40(20)60,labels labsize(medsmall) valuelabel  ) 							///
		ylabel(0.1(0.1)0.7,labsize(medsmall)format(%4.2f)) legend(off)						///
		scheme(white_brbg) xsize(5.5) ysize(3.5) legend(order(1 "Coefficient")) title("", size(*0.8)) saving("$results/fig_vi_1a.gph", replace)		 

use "$data/Benaho_com.dta", clear
drop if age_ccrecogn<-40 | age_ccrecogn>60
drop if fecha_nac<1920
collapse (mean) p21_3, by(fecha_nac)
twoway  (lpolyci p21_3 fecha_nac,m(circle)msize(small)mcolor(navy)lw(medthick)),	///
		xtitle("Year of birth",margin(medium)size(*1.4)) 							///
		ytitle(" ",margin(vvsmall)size(*0.8))										///
		legend(symplacement(north) cols(3) size(small) position(12) ring(1)) 		///			
		xlabel(1920(20)2000,labels labsize(medsmall) valuelabel  ) 					///
		ylabel(0.1(0.1)0.7,labsize(medsmall)format(%4.2f)) legend(off)				///
		scheme(white_brbg) xsize(5.5) ysize(3.5) legend(order(1 "Coefficient")) title("", size(*0.8)) saving("$results/fig_vi_1b.gph", replace)		 

graph combine "$results/fig_vi_1a.gph" "$results/fig_vi_1b.gph",scheme(white_brbg)col(2) xsize(7) ysize(3)
graph export "$results/fig_vi_1.png", replace
erase "$results/fig_vi_1a.gph"
erase "$results/fig_vi_1b.gph"

*Community membership (2012-)
use "$data/Benaho_com.dta", clear
drop if age_ccrecogn<-40 | age_ccrecogn>60
drop if fecha_nac<1920
keep if t>=2012
collapse (mean) p801_16, by(age_ccrecogn)
twoway  (lpolyci p801_16 age_ccrecogn,m(circle)msize(small)mcolor(navy)lw(medthick)),	  	///
		xtitle("Age at Year of community recognition",margin(medium)size(*1.4)) 			///
		ytitle(" " "Community membership (2012-)",margin(vvsmall)size(*1.4))				///
		legend(symplacement(north) cols(3) size(small) position(12) ring(1)) 				///			
		xlabel(-40(20)60,labels labsize(medsmall) valuelabel  ) 							///
		ylabel(0.3(0.1)0.9,labsize(medsmall)format(%4.2f)) legend(off)						///
		scheme(white_brbg) xsize(5.5) ysize(3.5) legend(order(1 "Coefficient")) title("",size(*.8)) saving("$results/fig_vi_2a.gph", replace)		 

use "$data/Benaho_com.dta", clear
drop if age_ccrecogn<-40 | age_ccrecogn>60
drop if fecha_nac<1920
keep if t>=2012
collapse (mean) p801_16, by(fecha_nac)
twoway  (lpolyci p801_16 fecha_nac,m(circle)msize(small)mcolor(navy)lw(medthick)),	///
		xtitle("Year of birth",margin(medium)size(*1.4)) 							///
		ytitle(" ",margin(vvsmall)size(*0.8))										///
		legend(symplacement(north) cols(3) size(small) position(12) ring(1)) 		///			
		xlabel(1920(20)2000,labels labsize(medsmall) valuelabel  ) 					///
		ylabel(0.3(0.1)0.9,labsize(medsmall)format(%4.2f)) legend(off)				///
		scheme(white_brbg) xsize(5.5) ysize(3.5) legend(order(1 "Coefficient")) title("",size(*.8))	saving("$results/fig_vi_2b.gph", replace)		 	
		
		
graph combine "$results/fig_vi_2a.gph" "$results/fig_vi_2b.gph",scheme(white_brbg)col(2) xsize(7) ysize(3)
graph export "$results/fig_vi_2.png", replace
erase "$results/fig_vi_2a.gph"
erase "$results/fig_vi_2b.gph"


********************************************************************************
*Appendix X. Addressing Migration
********************************************************************************

use "$data/Benaho_com.dta", clear
keep if nac_dist=="1"
*Outcomes
global out 			"p21_3 p801_16"
*Regressions by subsample
#delimit ;
foreach condition in 
"comm_less10k==1"
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/TableXb.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey year FE,YES) drop(i.fecha_nac i.t)
}
}		


use "$data/Benaho_com.dta", clear
gen migration_in = 1 if nac_dist=="0"
replace migration_in = 0 if nac_dist=="1"

areg migration_in i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if comm_less10k==1, absorb(ubigeo) vce(cluster comm_id)
test Dexp4_18_25- Dexp2_0_12=0
test Dexp4_18_25- Dexp3_13_18=0
test Dexp5_26_40- Dexp3_13_18=0


********************************************************************************
*Appendix XI. Robustness to Adding Community-Level Controls
********************************************************************************

use "$data/Benaho_com.dta", clear
*Outcomes
global out 			"p21_3 p801_16"
*Regressions by subsample
#delimit ;
foreach condition in 
"full==1"
"comm_less10k==1"
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer elevation_mean slope_mean land_mean rd_dens_06_vec mineria2 if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/TableXI.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey year FE,YES) drop(i.fecha_nac i.t)
}
}		


********************************************************************************
*Appendix XII. Additional Outcomes
********************************************************************************

use "$data/Benaho_com.dta", clear
*Outcomes
gen p558c_ind = 1 if p558c==1|p558c==2|p558c==3|p558c==9
replace p558c_ind = 0 if p558c==4|p558c==5|p558c==6

global out 			"p558c_ind"
*Regressions by subsample
#delimit ;
foreach condition in 
"full==1"
"comm_less10k==1"
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/TableXIIi.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey year FE,YES) drop(i.fecha_nac i.t)
}
}

*Outcomes
global out 			"p558c_ind"
*Regressions by subsample
#delimit ;
foreach condition in 
"full==1"
"comm_less10k==1"
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/TableXIIi.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey year FE,YES) drop(i.fecha_nac i.t)
}
}



use "$data/Benaho_com.dta", clear
*Outcomes
global out 			" p7 p1_08"
*Regressions by subsample
#delimit ;
foreach condition in 
"full==1"
"comm_less10k==1"
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/TableXIIii.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey year FE,YES) drop(i.fecha_nac i.t)
}
}
	

use "$data/Benaho_com.dta", clear
*Outcomes
global out 			" anoedu2"
*Regressions by subsample
#delimit ;
foreach condition in 
"full==1"
"comm_less10k==1"
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/TableXIIiii.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey year FE,YES) drop(i.fecha_nac i.t)
}
}



********************************************************************************
*Appendix XIII. Additional Alternative Explanations
********************************************************************************

use "$data/Benaho_com.dta", clear
*Outcomes
global out 			"anydisc "
*Regressions by subsample
#delimit ;
foreach condition in 
"full==1"
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/TableXIIIa.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey year FE,YES) drop(i.fecha_nac i.t)
}
}		

use "$data/Benaho_com.dta", clear
*Outcomes
global out 			"p21_3 p801_16 "
*Regressions by subsample
#delimit ;
foreach condition in 
"full==1 & norenewalvacanciapost==0"
{;
#delimit cr
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac i.t Dexp2_0_12 Dexp3_13_18 Dexp4_18_25 Dexp5_26_40 Dexp6_41_65 idorig mujer if `condition', absorb(ubigeo) vce(cluster comm_id)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/TableXIIIb.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey year FE,YES) drop(i.fecha_nac i.t)
}
}		


********************************************************************************
*Appendix XIV. Broader Effects of Recognition
********************************************************************************

use "$data/Altcontrolgroup.dta", clear
keep if (comm_pop<10000 & comm_pop!=0) | (estrato>5 & comm_pop==.)
global out "p21_3 p801_16"
foreach outcome of varlist $out {
areg `outcome' i.fecha_nac IDexp1_bef-IDexp6_41_65 idorig mujer, absorb(ubigeo) vce(cluster ubigeo)
local Clusters `e(N_clust)'
local Districts `e(k_absorb)'
outreg2 `outcome' using "$results/TableXIV.xslx", excel bdec(3) append addtext(FE,`e(absvar)',Clusters,`Clusters',Districts,`Districts',Year of birth FE,YES,District FE, YES,Survey year FE,YES) drop(i.fecha_nac)
}


